package com.newcoin.xgb.controller;

import com.newcoin.xgb.dto.RegisteredDto;
import com.newcoin.xgb.entity.Result;
import com.newcoin.xgb.service.XgbWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/web")
@Slf4j
public class XgbWebController {

    @Autowired
    private XgbWebService service;

    @GetMapping(value = "/registered")
    public String registered(Model model, String invCode) {
        model.addAttribute("inviteCode", invCode);
        return "webregistered";
    }
    @PostMapping(value = "/registered1")
    @ResponseBody
    public Result<String> registered1(RegisteredDto registeredDto){
        try {
            return service.registered(registeredDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result result = new Result();
            result.setCode(500);
            result.setMessage("注册失败");
            return result;
        }
    }
}
